package org.example.model;

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class MilkTea {
    public String milkName, imagePath, kind, condition;
    public double price;
    public int inventory;
    private static List<Integer> kindI;
    public MilkTea() {
        milkName = "";
        imagePath = "data/background/bag_icon.jpg";
        kind = "";
        condition = "上架";
        price = -1.0;
        inventory = 0;
    }
    public String savePhoto(String path) {
        FileDialog dialog = new FileDialog(new JFrame(), "选择图片", FileDialog.LOAD);
        dialog.setVisible(true);
        String imagePath = dialog.getDirectory() + dialog.getFile();
        if (!imagePath.equals("nullnull")) {
            try {
                FileInputStream reader = new FileInputStream(new File(imagePath));
                FileOutputStream writer = new FileOutputStream(new File("data/background/" + dialog.getFile()));
                byte[] bytes = new byte[1024];
                int n;
                while ((n = reader.read(bytes)) != -1) {
                    writer.write(bytes, 0, n);
                }
                imagePath = "data/background/" + dialog.getFile();
                reader.close();
                writer.close();
            } catch (FileNotFoundException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        else {
            imagePath = path;
        }
        return imagePath;
    }
}
